(function () {
    const elev = document.querySelector('.xtx-elevator');

    const back = document.querySelector('#backTop');

    window.addEventListener('scroll', function () {
        const rem = document.documentElement.scrollTop
        // if(rem >= 300){
        //     elev.style.opacity
        // }
        elev.style.opacity = rem >= 300 ? '1' : '0'
    })

    back.addEventListener('click', function () {
        window.scrollTo(0, 0)
    })

})();


(function () {
    const elev = document.querySelector('.xtx-elevator-list');

    const goodnew = document.querySelector('.xtx_goods_new');
    const popular = document.querySelector('.xtx_goods_popular');
    const brand = document.querySelector('.xtx_goods_brand');
    const topic = document.querySelector('.xtx_goods_topic');

    elev.addEventListener('click', function (e) {
        if (e.target.tagName === 'A' && e.target.dataset.name) {
            // console.log('1');
            const uname = e.target.dataset.name
            // const roll = document.documentElement.scrollTop
            switch (uname) {
                case 'goodnew':
                    window.scrollTo(0, goodnew.offsetTop)
                    break
                case 'popular':
                    window.scrollTo(0, popular.offsetTop)
                    break
                case 'brand':
                    window.scrollTo(0, brand.offsetTop)
                    break
                case 'topic':
                    window.scrollTo(0, topic.offsetTop)
                    break
                default: 
                    alert('出错了,有bug')
                

            }

        }
    })


    window.addEventListener('scroll',function(){
        // console.log(document.documentElement.scrollTop);
        const rem = document.documentElement.scrollTop

        elev.querySelector('a.active')  && elev.querySelector('a.active').classList.remove('active')

        if(rem >= goodnew.offsetTop && rem < popular.offsetTop){
            elev.querySelector('a[data-name="goodnew"]').classList.add('active')
        }else if(rem >= popular.offsetTop && rem < brand.offsetTop){
            elev.querySelector('a[data-name="popular"]').classList.add('active')
        }else if(rem >= brand.offsetTop && rem < topic.offsetTop){
            elev.querySelector('a[data-name="brand"]').classList.add('active')
        }else if(rem >= topic.offsetTop){
            elev.querySelector('a[data-name="topic"]').classList.add('active')
        }
        
        
    })
})();